'use strict';

class Util {
	constructor() {
		
	}
	
	/**
	 * 添加
	 */
	async add(event) {
		let { data = {}, userInfo, util } = event;
		let { vk } = util;
		let res = { code: 0, msg: '' };
		// 验证规则开始 -----------------------------------------------------------
		let rules = {
			title: [
				{ required: true, message: '标题为必填字段', trigger: 'blur' },
				{ min: 2, max: 100, message: '标题长度在 2 到 100 个字符', trigger: 'blur' }
			],
			type: [
				{ required: true, message: "类型为必选字段", trigger: "blur"}
			],
			cover: [
				{ required: true, message: "封面为必传字段", trigger: "blur"}
			]
		};
		// 验证规则结束 -----------------------------------------------------------
		
		// 开始进行验证
		res = vk.pubfn.formValidate({
			data: data,
			rules: rules
		});
		// 返回验证结果
		return res;
	}
	
	/**
	 * 修改
	 */
	async update(event) {
		let { data = {}, userInfo, util } = event;
		let { vk } = util;
		let res = { code: 0, msg: '' };
		
		// 验证规则开始 -----------------------------------------------------------
		let rules = {
			_id: [
				{ required: true, message: 'ID不能为空', trigger: 'blur' },
			],
			title: [
				{ required: true, message: '标题为必填字段', trigger: 'blur' },
				{ min: 2, max: 100, message: '标题长度在 2 到 100 个字符', trigger: 'blur' }
			],
			type: [
				{ required: true, message: "类型为必选字段", trigger: "blur"}
			],
			cover: [
				{ required: true, message: "封面为必传字段", trigger: "blur"}
			]
		};
		// 验证规则结束 -----------------------------------------------------------
		
		// 开始进行验证
		res = vk.pubfn.formValidate({
			data: data,
			rules: rules
		});
		// 返回验证结果
		return res;
	}
}

module.exports = new Util